package com.beasts.antpage.sh.controller;

import com.beasts.antpage.sh.entity.RemindMessage;
import com.beasts.antpage.sh.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 消息提醒
 * @author cn_zkn
 * @date 07/05/2018 8:39 AM
 * @since 1.0
 */
@Controller
@RequestMapping({"/message"})
public class MessageRemindController {

    @Autowired
    private IMessageService iMessageService;
    /**
     * 消息检索
     * @return
     */
    @RequestMapping({"/SearchMessageInfoByStatus"})
    @ResponseBody
    public List<RemindMessage> SearchMessageInfoByStatus(HttpServletRequest req) {
        List<RemindMessage> list = new ArrayList<RemindMessage>();
        try {

            String status = req.getParameter("status");
            String userId = req.getParameter("userId");
            list = iMessageService.findByStatus(status,userId);

        }catch(Exception e){
           e.printStackTrace();
        }

        return list;
    }

    /**
     * 消息检索 by EventCode
     * @return
     */
    @RequestMapping({"/SearchMessageInfoByEventCode"})
    @ResponseBody
    public RemindMessage SearchMessageInfoByEventCode(HttpServletRequest req) {
        RemindMessage message = new RemindMessage();
        try {

            String eventCode = req.getParameter("eventCode");
            message = iMessageService.findByEventCode(eventCode);

        }catch(Exception e){
            e.printStackTrace();
        }

        return message;
    }

    /**
     * 消息提醒新增
     * @return
     */
    @RequestMapping({"/RealtimeMessageServiceINF"})
    @ResponseBody
    public Map addMessage(HttpServletRequest req) {

        Map<String, Object> map = new HashMap<>();

        try {

            String eventCode = iMessageService.addMessage(req);
            map.put("EventStatus","0");
            map.put("EventCode",eventCode);

        }catch(Exception e){
            map.put("EventStatus","1");
            map.put("EventCode","");
        }

        return map;
    }

    /**
     * 消息提醒更新状态
     * @return
     */
    @RequestMapping({ "/UpdateMessageServiceINF"})
    @ResponseBody
    public Map<String, Object> authLogin(HttpServletRequest req, HttpServletResponse resp) {
        Map<String, Object> map = new HashMap<>();

        try {

            String eventCode = iMessageService.updateMessage(req);
            map.put("EventStatus","0");

        }catch(Exception e){
            map.put("EventStatus","1");
        }

        return map;
    }



}
